﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DevExpress.AgDataGrid;
using Test.Silverlight.DataGrid.EntitySvcProxy;

namespace Test.Silverlight.DataGrid
{
    public partial class General : UserControl
    {
        public General()
        {
            InitializeComponent();

            EntitySvcProxy.PersonServiceClient client=new PersonServiceClient();
            client.GetPersonsCompleted += new EventHandler<GetPersonsCompletedEventArgs>(client_GetPersonsCompleted);
            client.GetPersonsAsync(new SearchKey());
            client.CloseAsync();
        }

        void client_GetPersonsCompleted(object sender, GetPersonsCompletedEventArgs e)
        {
            this.dgPersons.Columns.Clear();

            foreach(PropertyInfo prop in typeof(Person).GetProperties())
            {
                AgDataGridColumn col=new AgDataGridColumn();
                col.HeaderContent = prop.Name;
                col.FieldName = prop.Name;
                this.dgPersons.Columns.Add(col);
            }
            this.dgPersons.DataSource = e.Result;
        }
    }
}
